
<template>
  <div class="home-container">
    <div class="first-page">
      <van-nav-bar left-text="家政平台" class="page-nav-bar" />
      <!-- 头部轮播图 -->
      <van-swipe class="my-swipe" :autoplay="3000">
        <van-swipe-item v-for="(image, index) in images" :key="index">
          <img v-lazy="image.img" />
        </van-swipe-item>
      </van-swipe>
      <!--/ 头部轮播图 -->
    </div>

    <!-- 方形导航 -->
    <van-grid class="square-item" :column-num="3">
      <van-grid-item text="入驻商务部" to="/enter" />
      <van-grid-item text="家政求职" to="/job" />
      <van-grid-item text="找家庭服务" to="/searchhouse" />
      <van-grid-item text="服务标准" to="/standard" />
      <van-grid-item text="家政保险" />
      <van-grid-item text="合同" />
    </van-grid>
    <!--/ 方形导航 -->

    <!-- 圆形导航 -->
    <div class="scope">
      <div
        class="yuesao"
        v-for="(value, index) in roundHeader"
        :key="index"
        @click="$router.push('/person')"
      >
        <van-image width="60" height="60" round :src="value.img"></van-image>
        <span>{{ value.name }}</span>
      </div>
    </div>

    <!--/ 圆形导航 -->

    <!-- 公司导航 -->
    <div class="hunan">
      <van-icon name="wap-home" size="19px" color="#979191" />
      湖南征信认证家服公司
    </div>

    <van-list
      :finished="finished"
      finished-text="没有更多了"
      @load="loadCompany"
    >
      <company-item
        v-for="(item, index) in companyList"
        :key="index"
        :company="item"
      ></company-item>
    </van-list>
    <div class="more" @click="$router.push('/house')">更多公司></div>

    <!--/ 公司导航 -->

    <!-- 家政公司人员导航 -->
    <div class="hunan">
      <van-icon name="manager" size="19px" color="#979191" />
      诚信注册家服员
    </div>

    <van-list
      :finished="finished"
      finished-text="没有更多了"
      @load="loadServers"
    >
      <servers-list
        v-for="(item, index) in serverWomenLiset"
        :showPingJia="true"
        :key="index"
        :servers="item"
      ></servers-list>
    </van-list>

    <!--/ 家政公司人员导航 -->
    <div class="more" @click="$router.push('/person')">更多人员></div>
  </div>
</template>
<script>
import { getBanner, getIntroduce, getCompany, getBabySitter, getroundById } from '@/api/home.js'
import CompanyItem from '@/components/company-item'
import ServersList from '@/components/servers-list'
export default {
  name: 'HomeIndex',
  components: {
    CompanyItem,
    ServersList
  },
  // 父组件给子组件传值
  props: {
    serversId: {
      type: [Number, String]
    }
  },
  data () {
    return {
      images: [],
      gridItemType: [],
      gridItemTypeRound: [],
      list: [],
      loading: false,
      finished: false,
      companyList: [],
      serverWomenLiset: [],
      roundHeader: []
    }
  },
  computed: {},
  watch: {},
  created () {
    // 初始化渲染
    this.loadBanner()
    this.loadIntroduce()
    this.loadServers()
    this.loadRoundById()
  },
  mounted () { },
  methods: {
    // 获取轮播图并赋值
    async loadBanner () {
      try {
        const res = await getBanner()
        this.images = res.data
      } catch (err) {
        this.$toast.fail('获取失败')
      }
    },
    async loadIntroduce () {
      try {
        const data = await getIntroduce(1)
        this.gridItemType = data.data
      } catch (err) {
        this.$toast.fail('获取失败')
      }
      try {
        const { data } = await getIntroduce(2)
        this.gridItemTypeRound = data
      } catch (err) {
        this.$toast.fail('获取失败')
      }
    },
    async loadCompany () {
      try {
        const data = await getCompany()
        this.companyList = data.data
      } catch (error) {
        this.$toast.fail('获取失败')
      }
    },
    async loadServers () {
      try {
        const { data } = await getBabySitter()
        this.serverWomenLiset = data
      } catch (err) {
        this.$toast.fail('获取失败')
      }
    },
    async loadRoundById () {
      try {
        const { data } = await getroundById()
        // console.log(data)
        this.roundHeader = data
      } catch (err) {
        this.$toast.fail('获取失败')
      }
    }
  }
}
</script>
<style lang="less" scoped>
.home-container {
  padding-bottom: 100px;
  background-color: #fff;
  .first-page {
    box-sizing: border-box;
    width: 750px;
    height: 426px;
    padding: 0 30px 10px 30px;
    background-color: #3f51b5;
    /deep/ .page-nav-bar .van-nav-bar__text {
      font-size: 32px;
      font-weight: 700;
      color: #fff;
    }
  }
  .my-swipe {
    width: 680px;
    height: 280px;
    img {
      height: 100%;
      width: 100%;
    }
  }
  /deep/.grid-round {
    .van-grid-item__content {
      width: 110px;
      height: 110px;
      border-radius: 50%;
      margin: 35px;
    }
  }
  /deep/.square-item {
    padding: 0 0 0 35px;
    .van-grid-item__content--center {
      width: 200px;
      height: 175px;
      margin: 30px 0px 16px 0px;
      border-radius: 12px;
      background-color: rgba(238, 236, 236, 100);
      border: 1px solid rgba(255, 255, 255, 100);
      color: black;
    }
  }
  .scope {
    width: 750px;
    height: 560px;
    border-radius: 8px;
    padding: 30px 40px;
    display: flex;
    box-sizing: border-box;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .yuesao {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 160px;
    span {
      font-size: 28px;
      padding: 23px 0;
    }
  }
  .more {
    font-size: 24px;
    color: #7b7777;
    height: 80px;
    text-align: center;
    // background-color: pink;
    align-items: center;
    line-height: 80px;
    // border-bottom: 20px solid #f9f5f5;
  }
  .hunan {
    font-size: 28px;
    border-bottom: 4px solid #f0eeee;
    padding-left: 30px;
    height: 84px;
    line-height: 84px;
    color: #101010;
    border-top: 20px solid #f9f5f5;
    .van-icon {
      transform: translateY(6px);
    }
  }
}
</style>
